package cn.tedu.music.admin.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonResolve {
    public  ArrayList<Map<String,Object>> jsonResolve(String  args) {
        ArrayList<Map<String,Object>> ret = new ArrayList<>();

        JSONObject jsonObject = JSON.parseObject(args);
//        System.out.println(jsonObject);
        JSONArray playlists = jsonObject.getJSONArray("playlists");
//        System.out.println(playlists.size());
        int size = playlists.size();
        for(int i = 0;i<size;i++) {
            HashMap map = new HashMap();
            JSONObject jsonObject1 = playlists.getJSONObject(i);
            String description = jsonObject1.getString("description");
            System.out.println(description);
            map.put("description",description);
            String coverImgUrl = jsonObject1.getString("coverImgUrl");
            System.out.println(coverImgUrl);
            map.put("coverImgUrl",coverImgUrl);
            String name = jsonObject1.getString("name");
            System.out.println(name);
            map.put("name",name);
            Long playCount = jsonObject1.getLong("playCount");
            System.out.println(playCount);
            map.put("playCount",playCount);
            ret.add(map);
        }
        return ret;

    }
}
